#pragma once
#include "reactor/noncopyable.hpp"
#include "reactor/channel.hpp"
#include <functional>
#include <netinet/in.h>
#include <string>

namespace reactor {
class EventLoop;

/**
 * @brief 用于接受新 TCP 连接的类
 */
class Acceptor : noncopyable {
public:
    using NewConnectionCallback = std::function<void(int sockfd, const struct sockaddr_in&)>;

    Acceptor(EventLoop* loop, const std::string& ip, uint16_t port);
    ~Acceptor();

    void setNewConnectionCallback(const NewConnectionCallback& cb) { _newConnectionCallback = cb; }
    void listen();
    bool listening() const { return _listening; }

private:
    void handleRead();

    EventLoop* _loop;
    int _acceptSocket;
    Channel _acceptChannel;
    NewConnectionCallback _newConnectionCallback;
    bool _listening;
};
} // namespace reactor
